package com.seres.listener;

import com.seres.listener.event.RedisDelEvent;
import com.seres.redis.RedisCache;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

/**
 * @Description : 事务提交成功后监听
 * @ClassName : TransactionalCommitSetexListener
 * @Author : 程磊
 * @Date: 2020-08-13 20:59
 */
@Slf4j
@Component
public class TransactionalCommitRedisDelListener {
    @Autowired
    private RedisCache redisCache;

    @TransactionalEventListener(fallbackExecution = true,phase= TransactionPhase.AFTER_COMMIT)
    public void handleClearTableCacheEvent(RedisDelEvent redisDelEvent){
        try{
          redisCache.getJedis().del(redisDelEvent.getKey());
        }catch (Throwable e) {
            log.error("{}");
        }
    }
}
